5aee2b
@@ -207,8 +207,7 @@
     // Properties with null values are ignored and exist only for the purpose of giving us
     // a symbolic name to reference in the Hive source code. Properties with non-null
     // values will override any values set in the underlying Hadoop configuration.
-    HADOOPBIN("hadoop.bin.path", System.getenv("HADOOP_HOME") + "/bin/hadoop"),
-    HADOOPCONF("hadoop.config.dir", System.getenv("HADOOP_HOME") + "/conf"),
+    HADOOPBIN("hadoop.bin.path", findHadoopBinary()),
     HADOOPFS("fs.default.name", null),
     HIVE_FS_HAR_IMPL("fs.har.impl", "org.apache.hadoop.hive.shims.HiveHarFileSystem"),
     HADOOPMAPFILENAME("map.input.file", null),
@@ -845,14 +844,6 @@
private void initialize(Class<?> cls) {
       addResource(hiveSiteURL);
     }
 
-    // if hadoop configuration files are already in our path - then define
-    // the containing directory as the configuration directory
-    URL hadoopconfurl = getClassLoader().getResource("core-site.xml");
-    if (hadoopconfurl != null) {
-      String conffile = hadoopconfurl.getPath();
-      this.setVar(ConfVars.HADOOPCONF, conffile.substring(0, conffile.lastIndexOf('/')));
-    }
-
     // Overlay the values of any system properties whose names appear in the list of ConfVars
     applySystemProperties();
 
@@ -913,6 +904,16 @@
private static void applyDefaultNonNullConfVars(Configuration conf) {
     }
   }
 
+  private static String findHadoopBinary() {
+    String val = System.getenv("HADOOP_HOME");
+    // In Hadoop 1.X and Hadoop 2.X HADOOP_HOME is gone and replaced with HADOOP_PREFIX
+    if (val == null) {
+      val = System.getenv("HADOOP_PREFIX");
+    }
+    // and if all else fails we can at least try /usr/bin/hadoop
+    return (val == null ? File.separator + "usr" : val) + File.separator + "bin" + File.separator + "hadoop";
+  }
+
   public Properties getChangedProperties() {
     Properties ret = new Properties();
     Properties newProp = getAllProperties();
